'use strict';


const db = uniCloud.database();
const dbCmd = db.command // 取指令

async function bookHotel(event){
	console.log(event)
	let { openid , hotelName , startDate , endDate , price , dayCount } = event
	let { name , phone , arriveTime , remark } = event.menberFrom
	const nowDay = new Date()
	let create_date = nowDay.toLocaleString()
	let data = {
		openid,
		hotel_id : event.hotelId,
		hotelName,
		name,
		phone,
		arriveTime,
		remark,
		startDate: event.startDate,
		endDate,
		status:0,
		create_date:create_date,
		price,
		dayCount
	}
	await db.collection('xinxuan_hotel').where({hotelName}).get().then((res)=>{
		data.uid = res.data[0].uid
	})
	let orderUpdateResult = await db.collection('order').add(data);
	
	if (orderUpdateResult.id || orderUpdateResult.updated === 1) {
		return {
			code: 0,
			msg: '预订成功'
		}
	}
	
	return {
		code: -1,
		msg: '预订失败'
	}
}

exports.main = bookHotel;